<!DOCTYPE html>
<html lang="en">
<head>
    {template 'common/edithead'}
    <!--微擎 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <style>
        .parameter{
            overflow: hidden;
        }
        .parameter>input:nth-child(1){
            width: 30%;
            float: left;
        }
        .parameter>input:nth-child(2){
            width: 70%;
            float: left;
        }
    </style>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    {template 'mymanage/webconfig/nav'}
                    <div class="x_content">
                        <br/>
                        <form class="form-horizontal" role="form" method="post" name="submit">
                            <input type="hidden" class="form-control"  name="list" value="">
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">校区选择</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[0]" value="{$list['content']['xc'][0]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">课程选择</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[1]" value="{$list['content']['xc'][1]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">学员姓名</label>
                                <div class="col-sm-8">
                                    {if $list['content']['name_status']==1}
                                    <input type="checkbox" checked class="js-switch" value="1" name="name_status">
                                    {else}
                                    <input type="checkbox" class="js-switch" name="name_status" value="1">
                                    {/if}
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">学员姓名</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[2]" value="{$list['content']['xc'][2]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">联系电话</label>
                                <div class="col-sm-8">
                                    {if $list['content']['mobile_status']==1}
                                    <input type="checkbox" checked class="js-switch" value="1" name="mobile_status">
                                    {else}
                                    <input type="checkbox" class="js-switch" name="mobile_status" value="1">
                                    {/if}
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">联系电话</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[3]" value="{$list['content']['xc'][3]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">优惠券</label>
                                <div class="col-sm-8">
                                    {if $list['content']['coupon_status']==1}
                                    <input type="checkbox" checked class="js-switch" value="1" name="coupon_status">
                                    {else}
                                    <input type="checkbox" class="js-switch" name="coupon_status" value="1">
                                    {/if}
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">优惠券</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[4]" value="{$list['content']['xc'][4]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-8">
                                    {if $list['content']['content_status']==1}
                                    <input type="checkbox" checked class="js-switch" value="1" name="content_status">
                                    {else}
                                    <input type="checkbox" class="js-switch" name="content_status" value="1">
                                    {/if}
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[5]" value="{$list['content']['xc'][5]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">推荐人</label>
                                <div class="col-sm-8">
                                    {if $list['content']['tui_status']==1}
                                    <input type="checkbox" checked class="js-switch" value="1" name="tui_status">
                                    {else}
                                    <input type="checkbox" class="js-switch" name="tui_status" value="1">
                                    {/if}
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">推荐人</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[6]" value="{$list['content']['xc'][6]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">应付学费</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xc[7]" value="{$list['content']['xc'][7]}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">自定义</label>
                                <div class="col-sm-8">
                                    {if $list['content']['list']}
                                    {loop $list['content']['list'] $index $item}
                                    <div class="input-group parameter" style="margin-bottom: 10px;">
                                        <input type="text" class="form-control" name="list_name" value="{$item['name']}" placeholder="名称">
                                        <input type="text" class="form-control" name="list_tip" value="{$item['tip']}" placeholder="提示文字">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    {/loop}
                                    {else}
                                    <div class="input-group parameter" style="margin-bottom: 10px;">
                                        <input type="text" class="form-control" name="list_name" value="" placeholder="名称">
                                        <input type="text" class="form-control" name="list_tip" value="" placeholder="提示文字">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    {/if}
                                </div>
                            </div>
                            <script>
                                var parameter={
                                    parameter_add:function(objc){
                                        $(objc).parent().after('<div class="input-group parameter" style="margin-bottom: 10px;">' +
                                                '<input type="text" class="form-control" name="list_name" value="" placeholder="名称">' +
                                                '<input type="text" class="form-control" name="list_tip" value="" placeholder="提示文字">' +
                                                '<span class="input-group-btn" onclick="parameter.parameter_add(this)">' +
                                                '<button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>' +
                                                '</span>' +
                                                '<span class="input-group-btn" onclick="parameter.parameter_del(this)">' +
                                                '<button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>' +
                                                '</span>' +
                                                '</div>')
                                    },
                                    parameter_del:function(objc){
                                        if($(objc).parent().siblings().length>0){
                                            $(objc).parent().remove();
                                        }
                                    }
                                }
                            </script>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">提交按钮文字</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="btn" value="{$list['content']['btn']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{template 'common/editfoot'}
<script>
    $(function(){
        $("input[name='submit']").click(function(){
            getJson();
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'saveform','version_id'=>$_GPC['version_id'])}",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
    });

    function  getJson(){
        var list=[];
        $("body").find(".parameter").each(function(){
            var name=$(this).find("input[name='list_name']").val();
            var tip=$(this).find("input[name='list_tip']").val();
            if(name!=""){
                var data={};
                data.name=name;
                data.tip=tip;
                list.push(data);
            }
        });
        if(list.length>0){
            $("input[name='list']").val(JSON.stringify(list));
        }
    }
</script>
</body>
</html>